import React, { Component } from "react";
//tom--->jerry         parent3(中转站)
class Parent3 extends Component{
    state={
        gift:null
    }
    callback=(opt)=>{
        console.log("收到给jerry的礼物",opt,"正在发送....");
        this.setState({
            gift:opt
        })
    }
    render(){
    return(
        <div>
        <Tom gifts={this.callback}></Tom>
        <hr/>
        <Jerry lw={this.state.gift}></Jerry>
        </div>
    )
    }
}
class Tom extends Component{
    state={
        gift:'滑板+溜冰鞋'
    }
    songli=()=>{
        this.props.gifts(this.state.gift)
    }
    render(){
        return(
            <div>
            <h1>Tom</h1>
            <button onClick={this.songli}>给Jerry送礼</button>
            </div>
        )
    }
}
class Jerry extends Component{
    render(){
        return(
            <div>
            <h1>Jerry</h1>
            <h2>收到Tom给我的礼物了:{this.props.lw}</h2>
            </div>
        )
    }
}
export default Parent3